package com.api.gbhg.liuwenbo.dao;

import com.api.gbhg.liuwenbo.utils.FormatUtil;
import com.kingbase8.util.LOGGER;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;

public class ProjectDetailsUtil {

    private static final Logger LOGGER = LoggerFactory.getLogger("gbhg");
    /**
     * 获取流程id
     * @param reId requestId
     * @return
     */
    public static String getFlowIdByRequestId(String reId){
        RecordSet rs = new RecordSet();
        String sql = " select workflowid from workflow_requestbase where requestid = "+reId+" ";
        rs.executeQuery(sql);
        rs.next();
        return rs.getString("workflowid");
    }

    /**
     * 获取流程标题
     * @param reId requestId
     * @return
     */
    public static String getFlowIdByRequestName(String reId){
        RecordSet rs = new RecordSet();
        String sql = " select requestname from workflow_requestbase where requestid = "+reId+" ";
        rs.executeQuery(sql);
        rs.next();
        return rs.getString("requestname");
    }

    /**
     * 选择框数值转换成显示值(字符串)
     * @param tabName 表名
     * @param val 数值
     * @param type 类型
     * @return
     */
    public static String getSelectionBoxVal(String tabName,int val,String type){
        RecordSet rs = new RecordSet();
        String sql = " select wf_si.selectvalue,wf_si.selectname from workflow_billfield wf_bf right join workflow_selectitem wf_si on wf_bf.id = wf_si.fieldid \n" +
                "where wf_bf.fieldname = '"+type+"' and wf_bf.detailtable = '"+tabName+"' ";
        rs.executeQuery(sql);
        while (rs.next()){
            if (rs.getInt("selectvalue") == val)
                return rs.getString("selectname");
        }
        return "";
    }


    /**
     * 定额标准值转换显示值
     * @param val
     * @return
     */
    public static String getDebztz(int val){
        RecordSet rs = new RecordSet();
        String sql = " select debzyr from uf_debztz  where id = "+val+" ";
        rs.executeQuery(sql);
        rs.next();
        return FormatUtil.DmFormat(rs.getDouble("debzyr"));
    }

    /**
     * 部门预算支出经济分类转换显示值
     * @param val
     * @return
     */
    public static String getJjzcflkmk(int val){
        RecordSet rs = new RecordSet();
        String sql = "select kmc from uf_jjzcflkmk where kdm = "+val+" ";
        rs.executeQuery(sql);
        rs.next();
        return rs.getString("kmc");
    }

    public static String getSyed(String requestid){
        return null;
    }

    /**
     * 计量单位转换成显示值
     * @param val
     * @return
     */
    public static String getLgcAssetUnit(int val){
        RecordSet rs = new RecordSet();
        String sql = "select unitname from LgcAssetUnit where unitmark = "+val+" ";
        rs.executeQuery(sql);
        rs.next();
        return rs.getString("unitname");
    }

    /**
     * 预算来源转换成显示值
     * @param val
     * @return
     */
    public static String getBudgetSources(int val){
        RecordSet rs = new RecordSet();
        String sql = "select yslymc from uf_budget_sources where id = "+val+" ";
        rs.executeQuery(sql);
        rs.next();
        return rs.getString("yslymc");
    }

    /**
     * 功能科目转换成显示值
     * @param val
     * @return
     */
    public static String getGnkm(int val){
        RecordSet rs = new RecordSet();
        String sql = "select kmmc from uf_gnkm where id = "+val+" ";
        rs.executeQuery(sql);
        rs.next();
        return rs.getString("kmmc");
    }

    /**
     * 地方财政拨款项目转换成显示值
     * @param val
     * @return
     */
    public static String getDfczbkxm(int val){
        RecordSet rs = new RecordSet();
        String sql = "select xmmc from uf_fzysrxm where id = "+val+" ";
        rs.executeQuery(sql);
        rs.next();
        return rs.getString("xmmc");
    }

    /**
     * 获取非中央分类得名称
     * @param id
     * @return
     */
    public static String getFlName(Integer id){
        RecordSet rs = new RecordSet();
        String sql = " select mc from uf_srysfl where id = "+id+" ";
        rs.executeQuery(sql);
        rs.next();
        return rs.getString("mc");
    }

    /**
     * 获取中央收入名称
     * @param id
     * @return 全路径中央财政收入名称
     */
    public static String getZysrName(String id){
        if (id.isEmpty())
            return "";
        RecordSet rs = new RecordSet();
        String sql ;
        String czsr_yj = new BaseBean().getPropValue("Verification", "yj");
        String[] srid = id.split("_");
        if (srid[0].equals(czsr_yj)){
            //这里不用修改了
            sql = " select (select subcompanyname from HrmSubCompany where id=dw)+'/'+kmdm as mc from uf_zyczbksr_km where id = "+srid[1]+" ";
            rs.executeQuery(sql);
            rs.next();
            return rs.getString("mc");
        }else{
            //这里要返回所有层级
            sql = " select (select subcompanyname from HrmSubCompany where id=dw)+'/'+(select kmdm from uf_zyczbksr_km where id=szgnkm)+'/'+srzx as mc from uf_zyczbksr_xj where id = "+srid[1]+" ";
            rs.executeQuery(sql);
            rs.next();
            return rs.getString("mc");
        }
    }


    /**
     * 获取非中央项目名称
     * @param id
     * @return
     */
    public static String getFzyxmName(String id){
        if (id.isEmpty())
            return "";
        RecordSet rs = new RecordSet();
        String sql = " select xmmc mc from uf_fzysrxm where id = "+id+" ";
        rs.executeQuery(sql);
        rs.next();
        return rs.getString("mc");
    }


    /**
     * 查询申报单位   SELECT `SUBCOMPANYNAME` FROM hrmsubcompany;
     * @param id
     * @return
     */
    public static RecordSet getSBDWById(String id){
        RecordSet rts=new RecordSet();
        String sql="select SUBCOMPANYNAME from hrmsubcompany where id in ("+id+") ";
        try {
            rts.executeQuery(sql);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rts;
    }
}
